package com.tanhua.manager.listeners;

import com.tanhua.autoconfig.templates.HuaWeiUGCTemplate;
import com.tanhua.domain.db.Log;
import com.tanhua.domain.mongo.Movement;
import com.tanhua.dubbo.api.mongo.MovementApi;
import com.tanhua.manager.service.LogService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@RocketMQMessageListener(topic = "movement_check_topic",consumerGroup = "movementCheckGroup")
public class QuanziCheckLinstener implements RocketMQListener<String> {


    @Autowired
    private LogService logService;

    @Autowired
    private HuaWeiUGCTemplate huaWeiUGCTemplate;

    @Reference
    private MovementApi movementApi;

    @Override
    public void onMessage(String movementId) {  // 0:未审核  1：通过 2：未通过
//        根据movementId获取movement
//        或movement中的文字和图片
        Movement movement = movementApi.queryMovementById(movementId);

        if(movement==null||movement.getState()!=0){
            return;
        }

        String textContent = movement.getTextContent();
        boolean textCheck = huaWeiUGCTemplate.textContentCheck(textContent);

        List<String> medias = movement.getMedias();
        boolean imageCheck = huaWeiUGCTemplate.imageContentCheck(medias.toArray(new String[]{}));

        if(textCheck&&imageCheck){
            movementApi.updateStateById(1,movementId);
        }else{
            movementApi.updateStateById(2,movementId);
        }

        System.out.println("内容已经审核成功..............");

    }
}
